package com.hjm.ui.comment.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.hjm.ui.R;
import com.hjm.ui.comment.entity.Comment;

import java.util.List;

public class CommentAdapter extends RecyclerView.Adapter<CommentAdapter.CommentAdapterHolder> {
    private List<Comment> commentList;
    private Context mcontext;

    public CommentAdapter(List<Comment> commentList, Context mcontext) {
        Log.d("评论适配器", "CommentAdapter: 获得的数据大小 "+commentList.size());
        this.commentList = commentList;
        this.mcontext = mcontext;
    }

    @NonNull
    @Override
    public CommentAdapterHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_comment,parent, false);
        return new CommentAdapterHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull CommentAdapterHolder holder, int position) {
        Comment comment = commentList.get(position);
        holder.userName.setText(comment.getUserName());
        holder.orderType.setText(comment.getGoodsType());
        holder.content.setText(comment.getText());
        holder.userPic.setImageBitmap(comment.getUserPicBitmap());
    }

    @Override
    public int getItemCount() {
        return commentList.size();
    }

    class CommentAdapterHolder extends RecyclerView.ViewHolder {
        private ImageView userPic;
        private TextView userName,orderType,content;

        public CommentAdapterHolder(@NonNull View itemView) {
            super(itemView);
            userPic = itemView.findViewById(R.id.image_view_pj_user_img);
            userName = itemView.findViewById(R.id.text_view_pj_user_name);
            orderType = itemView.findViewById(R.id.text_view_pj_select_type);
            content = itemView.findViewById(R.id.text_view_pj_content);
        }
    }
}
